/// <reference path="../../../../phaser.d.ts" />

import {
  PracticeScene
} from "./scene/practiceScene"
import {
  LoadScene
} from "./scene/loadScene"
import {
  OnLineScene
} from "./scene/onLineScene"
import {
  Socket
} from "./socket/socket"


export var game;
var config = {
  type: Phaser.AUTO,
  width: 500,
  height: 800,
  parent: 'gobang',
  physics: {
    default: 'arcade'
  },
  scene: [LoadScene, PracticeScene, OnLineScene]
}


// var wsUrl = "ws://192.168.3.24:2048/gobang"
var wsUrl = "ws://124.222.138.245:4263/gobang"

export function load(vue) {
  game = new Phaser.Game(config)
  game.Vue = vue
  game.ws = new Socket(wsUrl, game)
  game.account = {}

  // 屏幕兼容 全屏
  var canvas = document.querySelector('canvas');
  var windowWidth = window.innerWidth;
  var windowHeight = window.innerHeight;
  var windowRatio = windowWidth / windowHeight;
  var gameRatio = game.config.width / game.config.height;

  if (windowRatio < gameRatio) {
    canvas.style.width = windowWidth + 'px';
    canvas.style.height = (windowWidth / gameRatio) + 'px';
  } else {
    canvas.style.width = (windowHeight * gameRatio) + 'px';
    canvas.style.height = windowHeight + 'px';
  }
  return game
}
